package com.buka.user.controller;

import com.buka.user.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/delete")
public class DeleteServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //根据id 删除记录
        String id = req.getParameter("id");

        //删除逻辑
        UserService userService = new UserService();
        int delRows = userService.deleteById(id);

        if(delRows > 0) {
            //删除成功跳转到首页
            resp.sendRedirect("index.html");
        }else{
            //删除失败  跳转错误页面
            req.getRequestDispatcher("/WEB-INF/error.jsp").forward(req, resp);
        }
    }
}
